package org.nanotek.opencsv;

import au.com.bytecode.opencsv.bean.CsvToBean;
import au.com.bytecode.opencsv.bean.MappingStrategy;

public class HashMapCsvMapper extends CsvToBean<BaseMap>{

	public HashMapCsvMapper() {
	}


	@SuppressWarnings("unchecked")
	@Override
	public BaseMap processLine(MappingStrategy<BaseMap> mapper, String[] line) throws StrategyException{
		BaseMap bean = null;
		try { 
//			bean = mapper.createBean();
			bean = new BaseMap("");
			MapColumnStrategy <CsvBaseMapper, BaseMap> mapStrategy = (MapColumnStrategy<CsvBaseMapper, BaseMap>) mapper;
			CsvBaseMapper csvBaseMapper = mapStrategy.getCsvMapper(); 
			for (String key : csvBaseMapper.keySet()){ 
				bean.put(key, (line[csvBaseMapper.get(key)] !=null)? line[csvBaseMapper.get(key)].trim():"");
			}
//			for (int col = 0; col < line.length; col++) {
//				String key = mapper.getColumnName(col);
////				String value = (key !=null && line[col] !=null)? line[col].trim():"";
//				if (key !=null)
//					bean.put(key, (line[col] !=null)? line[col].trim():"");
//			}
			
		} catch (Exception e) 
		{ 
			throw new StrategyException (e);
		}
		return bean;
	}
}
